package com.harmontronics.hanma.paas.paas.domain.tenant.service;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.convert.Convert;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.harmontronics.hanma.paas.paas.domain.tenant.repository.persistence.HmTenantAppManagerRepository;
import com.harmontronics.hanma.paas.paas.domain.tenant.entity.HmTenantAppManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.harmontronics.hanma.paas.paas.common.PageBase;

import com.harmontronics.hanma.paas.paas.domain.tenant.repository.mapper.HmTenantAppManagerMapper;
import com.harmontronics.hanma.paas.paas.domain.tenant.repository.po.HmTenantAppManagerPO;
import java.util.List;

@Service("hmTenantAppManagerService")
public class HmTenantAppManagerService{

    @Autowired
    private HmTenantAppManagerRepository hmTenantAppManagerRepository;


    public HmTenantAppManager findById( Long id){
            HmTenantAppManagerPO po =   hmTenantAppManagerRepository.getById(id);
        return BeanUtil.toBean(po,HmTenantAppManager.class);
    }

    public void save(HmTenantAppManager hmTenantAppManager){
            HmTenantAppManagerPO po =  BeanUtil.toBean(hmTenantAppManager,HmTenantAppManagerPO.class);
            hmTenantAppManagerRepository.save(po);
    }

    public void update(HmTenantAppManager hmTenantAppManager){
            HmTenantAppManagerPO po =  BeanUtil.toBean(hmTenantAppManager,HmTenantAppManagerPO.class);
            hmTenantAppManagerRepository.updateById(po);
    }

    public void remove(List<Long> ids){
            hmTenantAppManagerRepository.removeByIds(ids);
    }

    public List<HmTenantAppManager> getList(){
        List<HmTenantAppManagerPO> pos =  hmTenantAppManagerRepository.list();
        return Convert.toList(HmTenantAppManager.class,pos) ;
    }

    public PageBase<HmTenantAppManager> getList(int pageNo,int pageSize){
        Page<HmTenantAppManagerPO> page = new Page<>(pageNo, pageSize);
        IPage<HmTenantAppManagerPO> resultPage =
                    hmTenantAppManagerRepository.selectPage(Wrappers.emptyWrapper(),page);
        return PageBase.from(resultPage,HmTenantAppManager.class);
    }

}